package com.jiazhong.IO流.数据流;

import java.io.*;

/**
 * 数据流
 */
public class DataStreamDemo {
    public static void main(String[] args) throws IOException {
        dataOutputStreamDemo();
        dataInputStreamDemo();
    }
    /**
     * 数据输出流
     */
    public static void dataOutputStreamDemo() throws IOException {
        //创建数据输出流对象
        DataOutputStream outputStream = new DataOutputStream(new FileOutputStream("d:/bcd.num"));
        outputStream.writeInt(256);
        outputStream.writeInt(1024);
        outputStream.writeInt(34223);
        outputStream.writeInt(432);
        outputStream.writeInt(242);
        outputStream.writeDouble(123.32);
        outputStream.flush();
        outputStream.close();
    }

    /**
     * 数据输入流
     */
    public static void dataInputStreamDemo() throws IOException {
        DataInputStream inputStream = new DataInputStream(new FileInputStream("d:/bcd.num"));
        while (true){
            try {
                int num = inputStream.readInt();
                System.out.println(num);
            } catch (EOFException e) {
                inputStream.close();
                System.out.println("文件读取结束");
                e.printStackTrace();
                break;
            }
        }

    }
}
